<template>
  <KView class="shop-mall-btn-group">
    <KView v-for="btn in btns" :key="`btn_${btn.id}`" class="flex-central" :class="{'select':btn.id===curBtn}" @click="btnClick(btn)">
      <span>{{btn.label}}</span>
    </KView>
  </KView>
</template>

<script>
  export default {
    props: {
      btns: {
        type: Array,
        required: true
      },
      curBtn: {
        type: String,
        required: true
      }
    },

    data() {
      return {};
    },

    methods: {
      btnClick(btn) {
        let id = btn.id;
        if (this.curBtn === id) {
          return;
        }

        this.$emit('update:curBtn', id);
        this.$emit('click', id);
      }
    }
  };

</script>

<style lang="scss">
  .shop-mall-btn-group {
    border: 1px solid #59c264;
    font-size: formatPx(32);
    color: #59c264;
    display: flex;
    border-radius: formatPx(10);

    >div {
      flex: 1;
      border-right: 1px solid #59c264;

      &:last-child {
        border-right: none;
      }

      &.select {
        background: #59c264;
        color: #ffffff;
      }
    }
  }

</style>
